﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using DevExpress.XtraReports.UI;
using DevExpress.XtraPivotGrid;
using System.Collections.Generic;
using DXApplicationTangche.UC.成品出库单.service;
using System.Data;
using DXApplicationTangche.Utils;
using DevExpress.XtraGrid.Demos.util;
using DXApplicationTangche.UC.订单一览新.订单预览新.service;
using DXApplicationTangche.UC.订单一览新.辅料.service;
using DXApplicationTangche.UC.款式尺寸;
using mendian;
using DXApplicationTangche.DTO;
using DXApplicationTangche.UC.货号管理.service;
using DXApplicationTangche.UC.项目流程.Service;
using DXApplicationTangche.UC.订单一览新.销售确认单;
using DXApplicationTangche.UC.面料审核.Service;
using DXApplicationTangche.UC.抖音出入库.Service;
using DXApplicationTangche.UC.下单MTO.Service;

namespace DXApplicationTangche.report
{
    public partial class XtraReport抖音出库单 : DevExpress.XtraReports.UI.XtraReport
    {
        private int total { get; set; }

        public XtraReport抖音出库单(List<DouyinRequestDTO> douyinRequestDTOs)
        {
            InitializeComponent();
            this.DetailReport.DataSource = douyinRequestDTOs;
            List<DouyinReportDetailDTO> douyinReportDetailDTOs明细 = new List<DouyinReportDetailDTO>();
            DouyinReportDetailDTO douyinReportDetailDTO = new DouyinReportDetailDTO();
            OrderCommitDTO返回 orderCommitDTO = new OrderCommitDTO返回();
            foreach (DouyinRequestDTO douyinRequestDTO in douyinRequestDTOs)
            {
                foreach(DouyinStockOutDetailDTO douyinStockOutDetailDTO in douyinRequestDTO.douyinStockOutDetailDTOs)
                {
                    orderCommitDTO = MTO订单Service.getOrderCommitDtoByBarcode(douyinStockOutDetailDTO.barcode);
                    douyinReportDetailDTO = new DouyinReportDetailDTO(douyinStockOutDetailDTO.barcode, douyinStockOutDetailDTO.styleNameCn, douyinStockOutDetailDTO.materialCode, orderCommitDTO.styleSizeCd);
                    douyinReportDetailDTO.build(douyinRequestDTO.price, douyinRequestDTO.requestQuantity, douyinRequestDTO.stockOutQuantity);
                    try { douyinReportDetailDTO.styleSizeCd = douyinReportDetailDTO.styleSizeCd.Replace("IGS_GROUP_SIZE-", "").Replace("EGS_GROUP_SIZE-", ""); } catch { }
                    douyinReportDetailDTOs明细.Add(douyinReportDetailDTO);
                }
                total += douyinRequestDTO.stockOutQuantity;
                douyinRequestDTO.styleSizeCd = (douyinRequestDTO.price * douyinRequestDTO.stockOutQuantity).ToString();
            }
            //DataTable dt = DataTableExtend.ToDataTable<DouyinReportDetailDTO>(douyinReportDetailDTOs明细);
            //this.xrPivotGrid分录.DataSource = dt;
            this.BindTableData(douyinRequestDTOs);
            this.BindData();
            this.DetailReport1.DataSource = douyinReportDetailDTOs明细;
            this.BindTableData采购订单();
        }


        /// <summary>
        /// 绑定表头
        /// </summary>
        private void BindData()
        {
            this.xrTableCell出库数量.Text = this.total.ToString();
            this.xrTableCell物料需求计划编码.Text = DateTime.Now.ToString();
        }

        private void BindTableData(List<DouyinRequestDTO> douyinRequestDTOs)
        {
            this.xrTableCell面料编码.DataBindings.Add("Text", douyinRequestDTOs, "styleNameCn");
            this.xrTableCell产成品需求数量.DataBindings.Add("Text", douyinRequestDTOs, "materialCode");
            //this.xrTableCell固定损耗.DataBindings.Add("Text", douyinRequestDTOs, "styleSizeCd");
            this.xrTableCell库存数量.DataBindings.Add("Text", douyinRequestDTOs, "price");
            this.xrTableCell未出库订单数量.DataBindings.Add("Text", douyinRequestDTOs, "requestQuantity");
            this.xrTableCell实际出库数.DataBindings.Add("Text", douyinRequestDTOs, "stockOutQuantity");
            this.xrTableCell已出库金额累计.DataBindings.Add("Text", douyinRequestDTOs, "styleSizeCd");
        }
        
        private void BindTableData采购订单()
        {
            this.xrTableCell采购订单号.DataBindings.Add("Text", DataSource, "styleNameCn");
            this.xrTableCell采购时间.DataBindings.Add("Text", DataSource, "materialCode");
            this.xrTableCell供应商.DataBindings.Add("Text", DataSource, "barcode");
            this.xrTableCell尺码.DataBindings.Add("Text", DataSource, "styleSizeCd");
        }
    }

}
